package com.geek.gkmember.biz.utils;

import com.geek.gkmember.facade.abs.AbstractResponse;
import com.geek.gkmember.util.excp.GkMemberCodeEnum;

/**
 * <h1>响应工具类。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2023/9/26 22:30
 */
public class RespUtils {

    /**
     * <h2>成功响应。</h2>
     *
     * @param: resp
     * @return: T
     */
    public static <T> T ok(AbstractResponse resp) {
        resp.setRespCode(GkMemberCodeEnum.SUCCESS.getCode());
        resp.setRespMsg(GkMemberCodeEnum.SUCCESS.getMsg());

        return (T) resp;
    }

    /**
     * <h2>失败响应。</h2>
     *
     * @param: resp
     * @param: excpCode
     * @param: excpMemo
     */
    public static <T> T fail(AbstractResponse resp,
                             String excpCode,
                             String excpMemo) {
        resp.setRespCode(excpCode);
        resp.setRespMsg(excpMemo);
        return (T) resp;
    }

    /**
     * <h2>失败响应。</h2>
     *
     * @param: resp
     * @param: excpCode
     * @param: excpMemo
     */
    public static <T> T fail(AbstractResponse resp,
                             GkMemberCodeEnum codeEnum) {
        resp.setRespCode(codeEnum.getCode());
        resp.setRespMsg(codeEnum.getMsg());
        return (T) resp;
    }
}